
package com.gitee.jmash.storage.service;

import java.util.List;
import java.util.UUID;
import com.gitee.jmash.core.orm.DtoPage;
import com.gitee.jmash.core.orm.DtoTotal;
import com.gitee.jmash.core.orm.cdi.JpaTenantService;
import com.gitee.jmash.core.orm.jpa.TenantEntityManager;
import com.gitee.jmash.core.orm.tenant.TenantService;
import com.gitee.jmash.core.transaction.JakartaTransaction;
import com.gitee.jmash.storage.dao.StorageOrganInfoDao;
import com.gitee.jmash.storage.entity.StorageOrganInfoEntity;
import jakarta.enterprise.inject.Typed;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import jakarta.transaction.Transactional.TxType;
import jakarta.validation.executable.ValidateOnExecution;
import jmash.storage.protobuf.StorageOrganInfoReq;

/**
 * storage_organ_info读服务.
 *
 * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
 */
@Typed(StorageOrganInfoRead.class)
@Transactional(TxType.SUPPORTS)
@JpaTenantService
@ValidateOnExecution
public class StorageOrganInfoReadBean implements StorageOrganInfoRead, JakartaTransaction {

  protected TenantEntityManager tem = new TenantEntityManager();

  protected StorageOrganInfoDao storageOrganInfoDao = new StorageOrganInfoDao(tem);

  @PersistenceContext(unitName = "ReadStorage")
  public void setEntityManager(EntityManager entityManager) {
    this.tem.setEntityManager(entityManager, false);
  }

  @Override
  public EntityManager getEntityManager() {
    return this.tem.getEntityManager();
  }

  @Override
  @SuppressWarnings("unchecked")
  public <T extends TenantService> T setTenant(String tenant) {
    this.tem.setTenant(tenant);
    return (T) this;
  }

  @Override
  public void setTenantOnly(String tenant) {
    this.tem.setTenantOnly(tenant);
  }

  @Override
  public String getTenant() {
    return this.tem.getTenant();
  }

  @Override
  public StorageOrganInfoEntity findById(UUID entityId) {
    return storageOrganInfoDao.find(entityId);
  }


  @Override
  public DtoPage<StorageOrganInfoEntity, DtoTotal> findPageByReq(StorageOrganInfoReq req) {
    return storageOrganInfoDao.findPageByReq(req);
  }

  @Override
  public List<StorageOrganInfoEntity> findListByReq(StorageOrganInfoReq req) {
    return storageOrganInfoDao.findListByReq(req);
  }

  @Override
  public List<StorageOrganInfoEntity> findMyStorageOrganList(List<String> serviceTypes,
      String unifiedId) {
    return storageOrganInfoDao.findMyStorageOrganList(serviceTypes, unifiedId);
  }

  @Override
  public StorageOrganInfoEntity findMyDefaultStorageOrgan(List<String> serviceTypes,
      String unifiedId) {
    return storageOrganInfoDao.findMyDefaultStorageOrgan(serviceTypes, unifiedId);
  }

  @Override
  public StorageOrganInfoEntity findOrganService(UUID organId, String serviceType) {
    return storageOrganInfoDao.findOrganService(organId, serviceType);
  }

  @Override
  public List<StorageOrganInfoEntity> findMyStorageOrganBrowseList(List<String> serviceTypes,
      String unifiedId) {
    return storageOrganInfoDao.findMyStorageOrganBrowseList(serviceTypes, unifiedId);
  }

  @Override
  public void close() throws Exception {
    CDI.current().destroy(this);
  }
}
